package A1动态规划;

public class LC_213打家劫舍II {
    public static void main(String[] args){
        int[] nums={2,3,2};
        System.out.println(rob(nums));
    }
    public static int rob(int[] nums) {
        if(nums==null || nums.length==0)
            return 0;
        if(nums.length==1)
            return nums[0];
        int res=Math.max(robI(nums,0,nums.length-1),robI(nums,1,nums.length));
        return res;
    }
    public static int robI(int[] nums,int start,int end) {
        int cur=0,temp=0,res=0;
        for(int i=start;i<end;i++){
            temp=res;
            res=Math.max(cur+nums[i],temp);
            cur=temp;
        }
        return res;
    }
}
